'''
Created on 15. jan. 2010

@author: perfp
'''
import unittest
from DependencyModule import Dependency


class Test(unittest.TestCase):

    def setUp(self):
        self.dependency = Dependency()
        
    def test1CanAddDependency(self):
        self.dependency.AddDirect('A', ['B', 'D'])
        
    def test2CanGetDependencyList(self):
        self.dependency.AddDirect('A', ['B'])
        dependencies = self.dependency.GetDependenciesFor('A')
        self.assertFalse(dependencies is None)
        self.assertEqual('B', dependencies[0])
        
    def test3WhenAddingMultipleDependencies_CanGetList(self):
        self.dependency.AddDirect('A', ['B', 'C', 'D'])
        dependencies = self.dependency.GetDependenciesFor('A')
        print dependencies[2]
        self.assertEqual('D', dependencies[2])
        
    def test4WhenAddingChaninedDependency_CanGetList(self):
        self.dependency.AddDirect('A', ['B'])
        self.dependency.AddDirect('B', ['C'])
        self.dependency.AddDirect('C', ['D'])
        dependencies = self.dependency.GetDependenciesFor('A')
        
        self.assertEqual(['B', 'C', 'D'], dependencies)
        
    def test5WhenAddingComplexGraph_CanGetList(self):
        self.dependency.AddDirect('A', ['B', 'C'])
        self.dependency.AddDirect('B', ['C', 'E'])
        self.dependency.AddDirect('C', ['G'])
        self.dependency.AddDirect('D', ['A', 'F'])
        self.dependency.AddDirect('E', ['F'])
        self.dependency.AddDirect('F', ['H'])
         
        self.assertEqual(['A', 'B', 'C', 'E', 'F', 'G', 'H'], self.dependency.GetDependenciesFor('D')
)
    

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()